﻿Imports System.Windows.Forms

Public Class frmUnlockApplication
    Dim strPassword As String

    Private Sub frmToolsLookUp_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Dim ds As DataSet = FillDataSet("Select PassWord, FirstName + ' ' + LastName as Name From tblUsers Where UserId=" & gintUserID)
            strPassword = ds.Tables(0).Rows(0).Item("PassWord")
            lblText.Text = "This application has been locked by """ & ds.Tables(0).Rows(0).Item("Name") & """." & vbCrLf & "Please enter password to release application."
            txtPassword.Focus()

        Catch ex As Exception
            MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
            AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
                Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
        End Try
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.DialogResult = DialogResult.Abort
        'gblnLockPermission = False
        Me.Close()
    End Sub
    Private Sub btnUnlock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUnlock.Click
        If CheckPassword() = True Then
            Me.DialogResult = DialogResult.Yes
            gblnLockPermission = False
            Me.Close()
        End If
    End Sub

    Private Function CheckPassword() As Boolean
        CheckPassword = False
        If txtPassword.Text = "" Then
            MessageBox.Show("Please enter Password", gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtPassword.Focus()
            Exit Function
        End If
        If TDecrypt(strPassword) <> Trim(txtPassword.Text) Then
            MessageBox.Show("Please enter correct Password", gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtPassword.Focus()
            Exit Function
        End If
        CheckPassword = True
    End Function
End Class